home *** CD-ROM | disk | FTP | other *** search
/ Komputer for Alle 2004 #2 / K-CD-2-2004.ISO / OpenOffice Sv / f_0397 / python-core-2.2.2 / lib / test / test_base64.py < prev    next >
Encoding:
Python Source  |  2003-07-18  |  2.2 KB  |  54 lines

  1. import unittest
  2. import test_support
  3. import base64
  4. from binascii import Error as binascii_error
  5.  
  6. class Base64TestCase(unittest.TestCase):
  7.     def test_encode_string(self):
  8.         """Testing encode string"""
  9.         test_support.verify(base64.encodestring("www.python.org") ==
  10.             "d3d3LnB5dGhvbi5vcmc=\n",
  11.             reason="www.python.org encodestring failed")
  12.         test_support.verify(base64.encodestring("a") ==
  13.             "YQ==\n",
  14.             reason="a encodestring failed")
  15.         test_support.verify(base64.encodestring("ab") ==
  16.             "YWI=\n",
  17.             reason="ab encodestring failed")
  18.         test_support.verify(base64.encodestring("abc") ==
  19.             "YWJj\n",
  20.             reason="abc encodestring failed")
  21.         test_support.verify(base64.encodestring("") ==
  22.             "",
  23.             reason="null encodestring failed")
  24.         test_support.verify(base64.encodestring(
  25.             "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789!@#0^&*();:<>,. []{}") ==
  26.             "YWJjZGVmZ2hpamtsbW5vcHFyc3R1dnd4eXpBQkNERUZHSElKS0xNTk9QUVJTVFVWV1hZWjAxMjM0\nNTY3ODkhQCMwXiYqKCk7Ojw+LC4gW117fQ==\n",
  27.             reason = "long encodestring failed")
  28.  
  29.     def test_decode_string(self):
  30.         """Testing decode string"""
  31.         test_support.verify(base64.decodestring("d3d3LnB5dGhvbi5vcmc=\n") ==
  32.             "www.python.org",
  33.             reason="www.python.org decodestring failed")
  34.         test_support.verify(base64.decodestring("YQ==\n") ==
  35.             "a",
  36.             reason="a decodestring failed")
  37.         test_support.verify(base64.decodestring("YWI=\n") ==
  38.             "ab",
  39.             reason="ab decodestring failed")
  40.         test_support.verify(base64.decodestring("YWJj\n") ==
  41.             "abc",
  42.             reason="abc decodestring failed")
  43.         test_support.verify(base64.decodestring(
  44.             "YWJjZGVmZ2hpamtsbW5vcHFyc3R1dnd4eXpBQkNERUZHSElKS0xNTk9QUVJTVFVWV1hZWjAxMjM0\nNTY3ODkhQCMwXiYqKCk7Ojw+LC4gW117fQ==\n") ==
  45.             "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789!@#0^&*();:<>,. []{}",
  46.             reason = "long decodestring failed")
  47.         test_support.verify(base64.decodestring('') == '')
  48.  
  49. def test_main():
  50.     test_support.run_unittest(Base64TestCase)
  51.  
  52. if __name__ == "__main__":
  53.     test_main()
  54.